package com.tian.arch.function.adapter.diff

import androidx.recyclerview.widget.ListUpdateCallback
import com.tian.arch.function.adapter.core.AbsAdapter

/**
 * 配合DiffUtil使用的ListUpdateCallback
 */
class LiteListUpdateCallback(
    private val mAdapter: AbsAdapter<*>
) : ListUpdateCallback {

    override fun onInserted(position: Int, count: Int) {
        mAdapter.notifyItemRangeInserted(mAdapter.notifyIndex(position), count)
    }

    override fun onRemoved(position: Int, count: Int) {
        mAdapter.notifyItemRangeRemoved(mAdapter.notifyIndex(position), count)
    }

    override fun onMoved(fromPosition: Int, toPosition: Int) {
        mAdapter.notifyItemMoved(
            mAdapter.notifyIndex(fromPosition),
            mAdapter.notifyIndex(toPosition)
        )
    }

    override fun onChanged(position: Int, count: Int, payload: Any?) {
        mAdapter.notifyItemRangeChanged(mAdapter.notifyIndex(position), count, payload)
    }

}